package org.rcy.framework.thrift.serializer;

import net.qiyuesuo.rpc.thrift.metadata.FieldValueMetaData;
import net.qiyuesuo.rpc.thrift.metadata.StructMetaData;
import net.qiyuesuo.rpc.thrift.tbase.ThriftStruct;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;

public class StructSerializer implements Serializer {

	@Override
	public Object read(TProtocol iprot, FieldValueMetaData valueMetaData) throws TException {
		ThriftStruct struct = new ThriftStruct((StructMetaData) valueMetaData, null);
		struct.read(iprot);
		return struct.getStructObject();
	}

	@Override
	public void write(TProtocol oprot, FieldValueMetaData valueMetaData, Object value) throws TException {
		ThriftStruct struct = new ThriftStruct((StructMetaData) valueMetaData, value);
		struct.write(oprot);
	}
}
